/**
 * Label représentant un mot possible.
 * 
 * @author Marie-Hélène Goddet, Damien Finck, Cédric Schaller
 * 
 */
package gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JLabel;

@SuppressWarnings("serial")
public class JMot extends JLabel {
	
	private ActionListener actionListener;
	
	/**
	 * Constructeur
	 * @param text le texte à afficher
	 * @param alignment l'endroit où placer le mot
	 */
	public JMot(String text,int alignment) {
		/** Evénements **/
		MouseListener mouse = new Event_JMot(this);
		this.addMouseListener(mouse);
		/** Paramètres **/
		this.setText(text);
		this.setHorizontalAlignment(alignment);
		Font f = new Font("Monospaced",0,14);
		this.setFont(f);
		this.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
		//this.setToolTipText(text);
	}
	public void addActionListener(ActionListener actionListener) {
		this.actionListener = actionListener;
	}
	public ActionListener getActionListener() {
		return actionListener;
	}
}
class Event_JMot implements MouseListener {
	JMot jl;
	/**
	 * Constructeur
	 * @param jl le label contenant le choix
	 */
	public Event_JMot(JMot jl) {
		this.jl=jl;
	}
	/**
	 * Si on clique sur le choix
	 */
	@Override
	public void mouseClicked(MouseEvent arg0) {
		ActionEvent e = new ActionEvent(jl,1,"JMot_selection");
		jl.getActionListener().actionPerformed(e);
	}
	/**
	 * Si on survole le choix
	 */
	@Override
	public void mouseEntered(MouseEvent arg0) {
		jl.setBorder(BorderFactory.createLineBorder(Color.BLUE));
	}
	@Override
	public void mouseExited(MouseEvent arg0) {
		jl.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
	}
	@Override
	public void mousePressed(MouseEvent arg0) {
		
	}
	@Override
	public void mouseReleased(MouseEvent arg0) {
		
	}
}